package com.dean.pokeking.ui.pages

import android.view.View.OnClickListener
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.dean.pokeking.beans.PlaceButton

/**
 * @ClassName PlaceChoosePage
 * @Description PlaceChoosePage
 * @Author Dean
 * @Date 2023/3/2
 * @Version 1.0
 */

@Composable
fun PlaceChoosePage(
    modifier: Modifier = Modifier,
    placeButtonList: List<String>,
    onClick: (placeName: String) -> Unit
) {
    LazyVerticalGrid(
        modifier = modifier.fillMaxSize(),
        columns = GridCells.Fixed(2),
        contentPadding = PaddingValues(10.dp)
    ) {
        items(items = placeButtonList, key = { it }) {
            PlaceButtonCell(title = it, onClick = { onClick(it) })
        }
    }
}

@Composable
fun PlaceButtonCell(
    title: String,
    onClick: () -> Unit = {}
) {
    Card(
        modifier = Modifier
            .width(150.dp)
            .height(150.dp)
            .padding(10.dp)
            .clip(RoundedCornerShape(15.dp))
            .clickable { onClick() },
        shape = RoundedCornerShape(15.dp),
    ) {
        Box(
            modifier = Modifier
                .fillMaxSize()
                .background(Color.Gray.copy(alpha = 0.2f)),
            contentAlignment = Alignment.Center
        ) {
            Text(text = title, fontSize = 30.sp)
        }
    }
}

@Composable
@Preview(showBackground = true)
fun PlaceButtonPreview() {
    PlaceButtonCell(title = "神奥联盟")
}






